<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="订单编号" prop="orderCode">
              <el-input
                v-model="queryParams.orderCode"
                placeholder="请输入订单编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="计划编号" prop="planNumber">
              <el-input
                v-model="queryParams.planNumber"
                placeholder="请输入计划编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="供货日期" prop="materialDeadline">
              <el-date-picker clearable
                              v-model="queryParams.materialDeadline"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择供货日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="供应商名称" prop="vendorName">
              <el-input
                v-model="queryParams.vendorName"
                placeholder="请输入供应商名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="付款类型" prop="paymentType">
              <el-select v-model="queryParams.paymentType" placeholder="请选择付款类型" clearable>
                <el-option
                  v-for="dict in dict.type.erp_payment_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="   ">
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-row :gutter="10" class="mb8">

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table border v-loading="loading" :data="orderList" >
        <el-table-column label="订单编号" align="center" prop="orderCode" width="190">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="handleInfo(scope.row)"
              v-hasPermi="['mes:cg:order:query']"
            >{{scope.row.orderCode}}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="计划编号" width="150" align="center" prop="planNumber"/>
        <el-table-column label="计划名称" width="160" align="center" prop="planName" :show-overflow-tooltip="true"/>
        <el-table-column label="供货日期" align="center" prop="materialDeadline" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.materialDeadline, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="供应商名称" width="160" align="center" prop="vendorName" :show-overflow-tooltip="true"/>
        <el-table-column label="联系人" align="center" prop="contact"/>
        <el-table-column label="电话" align="center" prop="contactTel"/>
        <el-table-column label="付款类型" align="center" prop="paymentType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.erp_payment_type" :value="scope.row.paymentType"/>
          </template>
        </el-table-column>

        <el-table-column label="成本" width="120" align="center" prop="estimatedCost">
          <template slot-scope="scope">
            <el-tag type="danger">{{ formatCurrency(scope.row.estimatedCost) }}</el-tag>
          </template>
        </el-table-column>
<!--        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <el-tag type="info" v-if="scope.row.approvalStatus === 0">草稿</el-tag>

          </template>
        </el-table-column>-->
        <el-table-column fixed="right" label="操作" align="center" width="250">
          <template slot-scope="scope">
            <el-tooltip content="审核" placement="top">
              <el-button
                size="mini"
                type="primary"
                icon="el-icon-s-check"
                @click="handleGoApprove(scope.row)"
                v-hasPermi="['mes:cg:order:approve']"
              >
              </el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <ApproveView ref="infoView"  :approve-flag="approveFlag"></ApproveView>
  </div>
</template>

<script>
import {listApproveOrder} from "@/api/mes/cg/order";

import Add from "@/views/mes/cg/order/add.vue";
import ApproveView from "@/views/mes/cg/order/approveView.vue";


export default {
  name: "Plan",
  components: {

    Add,
    ApproveView
  },
  dicts: ['erp_payment_type'],
  data() {
    return {
      approveFlag:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购计划表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planName: null, planDate: null, materialDeadline: null, approvalStatus: null,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    formatCurrency(number) {
      return new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY' }).format(number);
    },
    /** 查询采购计划列表 */
    getList() {
      this.loading = true;
      listApproveOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 查看按钮操作 */
    handleInfo(row) {
      this.$refs.infoView.open = true;
      this.$refs.infoView.optType = 'view';
      this.approveFlag=false;
      this.$refs.infoView.init(row.id);
    },
    handleGoApprove(row){
      this.$refs.infoView.open = true;
      this.approveFlag=true;
      this.$refs.infoView.init(row.id);
    },
  }
};
</script>
